package test.administrator.example.com.mvptest1.framework.support.viewstate.activity;

import android.support.annotation.NonNull;

import test.administrator.example.com.mvptest1.framework.support.activity.MvpActivity;
import test.administrator.example.com.mvptest1.framework.MvpPresenter;
import test.administrator.example.com.mvptest1.framework.MvpView;
import test.administrator.example.com.mvptest1.framework.support.activity.ActivityMvpDelegate;
import test.administrator.example.com.mvptest1.framework.support.viewstate.ViewState;
import test.administrator.example.com.mvptest1.framework.support.viewstate.MvpViewStateDelegateCallback;

/**
 * 代理一：针对于生命周期->代理对象(持有目标对象的引用)
 * 代理二：针对ViewState缓存->目标对象
 * <p>
 * 备忘录模式->创建备忘录角色->创建备忘录->MvpViewStateActivity
 * Created by thinkpad on 2018/8/6.
 */
public class MvpViewStateActivity<V extends MvpView, P extends MvpPresenter<V>, VS extends ViewState<V>> extends MvpActivity<V, P> implements MvpViewStateDelegateCallback<V, P, VS> {

	private VS viewState;
	//是否已经恢复状态
	protected boolean restoringViewState = false;

	@Override
	public ActivityMvpDelegate<V, P> getMvpDelegate() {
		if (mvpDelegate == null) {
			mvpDelegate = new ActivityMvpViewStateDelegateImpl<V, P, VS>(this, this, true);
		}
		return super.getMvpDelegate();
	}

	@Override
	public VS getViewState() {
		return viewState;
	}

	@Override
	public void setViewState(VS viewState) {
		this.viewState = viewState;
	}

	@NonNull
	@Override
	public VS createViewState() {
		return null;
	}

	@Override
	public void setRestoringViewState(boolean restoringViewState) {
		this.restoringViewState = restoringViewState;
	}

	@Override
	public boolean isRestoringViewState() {
		return restoringViewState;
	}

	@Override
	public void onViewStateInstanceRestored(boolean instanceStateRetained) {

	}

	@Override
	public void onNewViewStateInstance() {

	}

}

























































































